/**************************************************
获取分数-绩效合同
* */
<template>
  <div class="mod-config">
    <basic-container>
      <div v-if="hideScoreView">
        <div>
          <div :height="searchheight">
          <span style="float:right;margin-top:-20px;margin-bottom:20px;cursor: pointer;" @click="searchchangeadvanced">
            {{ searchadvanced ? "查询条件收起" : "查询条件展开" }}
            <i :class="searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"/>
          </span>
            <div v-show="searchadvanced">
              <el-form
                :inline="true"
                :model="searchForm"
                @keyup.enter.native="getDataList()"
                class="form-inline">
                <el-form-item label="统计名称">
                  <selectSearch @getDataByTjmc="getDataByTjmc"></selectSearch>
                </el-form-item>
                <el-form-item>
                  <el-button
                    icon="el-icon-search"
                    type="primary"
                    class="marginLeft"
                    @click="getDataList()"
                  >检索</el-button>
                </el-form-item>
              </el-form>
            </div>
          </div>
          <div class="boxContain" >
            <!--操作按钮-->
            <div>
              <el-button type="primary" @click="addAndEditOpera()">新增</el-button>
            <!--  <el-button type="danger" @click="delData()" :disabled="canDelete">删除</el-button>-->
            </div>
            <div><el-button type="primary" @click="exportExcel()">导出</el-button></div>
          </div>

          <!--数据列表-->
          <el-table
            style="width: 100%;margin-top:20px"
            :data="dataList"
            border
            header-align="center"
            v-loading="dataListLoading"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55" align="center"></el-table-column>
            <el-table-column type="index" width="55" align="center"  label="序号" ></el-table-column>
            <el-table-column prop="tjmc" align="center" min-width="100" label="统计名称" show-overflow-tooltip>
              <template slot-scope="scope">
                  <span
                    @click="addAndEditOpera(scope.row)"
                    style="color:rgb(14, 37, 140);cursor:pointer"
                  >{{scope.row.hzzqmc}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="bz" align="center"  label="备注" show-overflow-tooltip></el-table-column>
            <el-table-column prop="dataTqsj" align="center"  label="数据提取时间" min-width="110" show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.startDate}}至{{scope.row.endDate}}
              </template>
            </el-table-column>
            <el-table-column prop="state" align="center"  label="状态">
              <template slot-scope="scope">
                {{scope.row.state|transState(scope.row.lx)}}
              </template>
            </el-table-column>
            <el-table-column prop="createTime" align="center"  label="创建时间"></el-table-column>
            <el-table-column align="center"  fixed="right" label="操作" min-width="100">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  plain
                  size="small"
                  @click="synchronizesData(scope.row)">同步数据</el-button>
                <el-button
                  type="primary"
                  plain
                  size="small"
                  @click="showScoreView(scope.row)">生成得分</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!--分页-->
          <div class="avue-crud__pagination">
            <el-pagination
              @size-change="sizeChangeHandle"
              @current-change="currentChangeHandle"
              :current-page="pageData.pageIndex"
              :page-sizes="[10, 20, 50, 100]"
              :page-size="pageData.pageSize"
              :total="pageData.totalPage"
              background
              layout="total, sizes, prev, pager, next, jumper"
            ></el-pagination>
          </div>
        </div>
        <addAndEditDialog ref="addEditDialogShow" v-if="addEditDialogShow" @refreshDataList="refreshDataList"></addAndEditDialog>
      </div>
      <div v-else>
         <getScoreView @closeDialog="closeDialog" ref="scoreView"></getScoreView>
      </div>
    </basic-container>
  </div>
</template>

<script>
    import addAndEditDialog from "@/views/statisticsanalysis/components/addAndEditDialog";
    import selectSearch from "@/views/statisticsanalysis/components/selectSearch";
    import getScoreView from "@/views/statisticsanalysis/components/getScoreView";
    // 接口 api
    import {fractionList, scoreExportExcel, synchronousData,transState} from "@/api/statisticsanalysis/fractionGet.js";
    import { mapGetters} from "vuex";
    import store from "@/store";
    export default {
        data(){
            return {
                headers: {
                    Authorization: "Bearer " + store.getters.access_token
                },
                searchForm: {isld:'0'}, //查询表单
                canDelete: true, // 删除表格数据的禁用
                multipleSelection: [], //表格中被选中的数据
                dataList: [],
                dataListLoading: false,
                searchadvanced: true,
                searchheight: "0",
                addEditDialogShow:false,
                menuType:'gzrws',//ht rckh pf zdrw gzrws
                hideScoreView:true,
                pageData: {
                    //分页对象
                    pageIndex: 1,
                    pageSize: 10,
                    totalPage: 0
                },
            };
        },
        components: {
            selectSearch,//下拉选搜索组件
            addAndEditDialog,
            getScoreView//生成得分的组件
        },
        filters: {
            transState
        },
        computed: {
            ...mapGetters(["permissions"])
        },
        watch: {

        },
        created() {
            this.getDataList();
        },
        methods: {
            //选择统计名称执行搜索功能
            getDataByTjmc(tjmc){
                this.searchForm.hzzqmc = tjmc ;
                this.getDataList() ;
            },
            //新增或者编辑操作
            addAndEditOpera(obj) {
                this.addEditDialogShow = true;
                this.$nextTick(() => {
                    if (obj){
                        this.$refs.addEditDialogShow.init(obj,this.menuType,'edit');
                    }else{
                        this.$refs.addEditDialogShow.init('',this.menuType,'add');
                    }
                });
            },
            //同步数据
            synchronizesData(row){
                this.$confirm(`确定要提取"${row.hzzqmc}"数据吗`, "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        synchronousData(row.id,this.menuType).then(r => {
                            if (r.data.code == 0) {
                                this.$message.success("数据同步成功");
                                this.getDataList();
                            } else {
                                this.$message.error(r.data.msg);
                                this.getDataList();
                            }
                        });
                    })
                    .catch(() => {
                    });
            },
            showScoreView(row){
                this.hideScoreView = false ;
                this.$nextTick(() => {
                    this.$refs.scoreView.init(row.id,this.menuType);
                })
            },
            // 删除数据
            delData() {
                // 删除只能删除状态为0  1 的数据
                this.$confirm("此操作将删除选中的数据, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        let ids = this.multipleSelection.map(it => {
                            return it.id;
                        });
                        deleteChoose(ids.toString()).then(r => {
                            if (r.data.code == 0) {
                                this.$message.success("删除成功");
                                this.getDataList();
                            } else {
                                this.$message.error(r.data.msg);
                                this.getDataList();
                            }
                        });
                    })
                    .catch(() => {
                        this.$message({
                            type: "info",
                            message: "已取消删除"
                        });
                    });
            },
            // 勾选数据
            handleSelectionChange(val) {
                if (val.length == 0) {
                    this.canDelete = true;
                } else{
                    this.canDelete = false ;
                }
                this.multipleSelection = val;
            },
            // 查询条件的展开关闭
            searchchangeadvanced() {
                this.searchadvanced = !this.searchadvanced;
                if (this.searchadvanced) {
                    this.searchheight = "auto";
                }
            },

            // 获取数据列表
            getDataList() {
                this.dataListLoading = true;
                this.searchForm.lx = this.menuType ;
                fractionList(
                    Object.assign(
                        {
                            current: this.pageData.pageIndex,
                            size: this.pageData.pageSize,
                        },
                        this.searchForm
                    )
                )
                    .then(r => {
                        if (r.data.code == 0) {
                            this.dataListLoading = false ;
                            this.dataList = r.data.data.records ;
                            this.pageData.totalPage = r.data.data.total;
                        }
                    })
                    .catch(err => {});
            },
            //刷新界面
            refreshDataList(){
                this.getDataList() ;
            },
            // 关闭弹窗
            closeDialog() {
                this.getDataList() ;
                this.hideScoreView = true ;
            },
            //导出
            exportExcel(){
                let data = this.multipleSelection;
                if (data.length == 0) {
                    this.$message.closeAll();
                    this.$message.warning("请选择一个工作！");
                    return;
                }
                let filename = "工作任务书" + ".xlsx";
                let ids = [];
                for (let i = 0; i < data.length; i++) {
                    ids.push(data[i].id);
                }
                scoreExportExcel({
                    ids: ids
                }).then(response => {
                    this.$message.closeAll();
                    this.$message.success("导出成功!");
                    let url = window.URL.createObjectURL(new Blob([response.data]));
                    let link = document.createElement("a");
                    link.style.display = "none";
                    link.href = url;
                    link.setAttribute("download", filename);
                    document.body.appendChild(link);
                    link.click();
                });
            },
            // 条数变化
            sizeChangeHandle(val) {
                this.pageData.pageSize = val;
                this.pageData.pageIndex = 1 ;
                this.getDataList();
            },
            // 页码分页变化
            currentChangeHandle(val) {
                this.pageData.pageIndex = val;
                this.getDataList();
            },
        }
    };
</script>

<style lang="scss" scoped>
 .boxContain{padding-bottom: 10px;border-bottom:1px solid rgb(176, 189, 226);display: flex;justify-content: space-between;width: 100%}
</style>
